﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using SpectrumAnalyser.Config.Client;
using SpectrumAnalyser.Config.Contract;

namespace SpectrumAnalyser.Config.Service
{
    class Program
    {
        internal class ServiceConsole : ConfigService
        {
            public ServiceConsole(IUnityContainer unityContainer)
                : base(unityContainer)
            {
            }

            public void Run(string[] args)
            {
                base.OnStart(args);
                Console.WriteLine("Press any key to stop");
                Console.ReadKey();

                base.OnStop();
            }
        }


        static void Main(string[] args)
        {
            //"net.tcp://localhost/ConfigService"

            var unityContainer = new UnityContainer();

            unityContainer.AddNewExtension<Interception>();

            unityContainer.RegisterInstance<IConfigService>(unityContainer.Resolve<ConfigServiceController>());

            unityContainer.Configure<Interception>()
                .SetInterceptorFor<IConfigService>(new TransparentProxyInterceptor());

            //run service with console
            unityContainer.Resolve<ServiceConsole>().Run(new string[] {});
        }
    }
}
